package gui;

import java.util.List;

import model.Field;
import model.Location;
import model.MapObject;
import model.Sniper;
import model.SuperMob;

public class Simulator {


	private int rows;
	private int cols;
	private SimulatorView view;
	private Field field;
	private int level = 1;
	private int playerHp = 50;



	public Simulator(int depth, int width){
		this.cols = width;
		this.rows = depth;
		this.field = new Field(depth,width);
		this.view = new SimulatorView(depth, width, field);
		createMobs();
		createMap();

	}

	public void createMobs(){
		Location loc = new Location(1,2);

		Location loc1 = new Location(2,2);

		//		Location loc1 = new Location(29,29);
		field.createSuperMob();
		field.createSniperTower(loc);
		field.createSuperWall(loc1);
		//		field.createSniperTower(loc1);

	}
	public void createMap(){

		for (int row = 0; row < field.getDepth(); row++) {
			Location location = new Location(row,0);
			field.createSuperWall(location);
		}
		for (int row = 0; row < field.getDepth(); row++) {
			Location location = new Location(row,field.getWidth()-1);
			field.createSuperWall(location);

		}
		for (int col = 0; col < field.getWidth(); col++) {
			Location location = new Location(0,col);
			field.createSuperWall(location);

		}
		for (int col = 0; col < field.getWidth(); col++) {
			Location location = new Location(field.getDepth()-1,col);
			field.createSuperWall(location);

		}
		
		
		
	}


	public void startUp(){
		level++;
		view.prePaintPanel(field);
	}

	public void movementFieldStepOne(){

		view.prePaintPanel(field);

		for (int row = field.getDepth()-1; row >= 0; row--) {
			for (int col = field.getWidth()-1; col >= 0; col--) {
				MapObject mo = (MapObject) field.getObjectAt(row, col);
				if(mo != null && mo.isMovable()!= false){
					if(field.getObjectAt(row, col+1) != null){
						field.clearLocation(mo.getLocation());
						Location loc = new Location(row+1,col);
						mo.setLocation(loc);
						field.place(mo,loc);
						System.out.println("Row : " + row + " Col : " + col + " FLYTTES");

					}
					if(field.getObjectAt(row, col+1) == null){
						field.clearLocation(mo.getLocation());
						Location loc = new Location(row, col+1);
						mo.setLocation(loc);
						field.place(mo, loc);
					}
					else if (field.getObjectAt(row, col+1) == null && field.getObjectAt(row, col+1) != null){
						field.clearLocation(mo.getLocation());
						Location loc = new Location(row-1,col);
						mo.setLocation(loc);
						field.place(mo, loc);
						System.out.println("Row : " + row + " Col : " + col + " FLYTTES OOOOOOP !");
						
					}
					
					
				}else{
					System.out.println("Row : " + row + " Col : " + col + " ER NULL");

				}


			}
		}
		view.repaint();
	}

	


	public SimulatorView getView() {
		return view;
	}


	public void setView(SimulatorView view) {
		this.view = view;
	}


	public Field getField() {
		return field;
	}


	public void setField(Field field) {
		this.field = field;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public int getCols() {
		return cols;
	}

	public void setCols(int cols) {
		this.cols = cols;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}




}
